package nl.sogyo.objectvisualisatie.GUI;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JToolBar;

import nl.sogyo.objectvisualisatie.core.Model;


@SuppressWarnings("serial")
public class ToolBar extends JPanel implements ActionListener{
	
	private JToolBar toolBar;
	protected JTextArea textArea;
	private Model model;

  public ToolBar() {
    super(new BorderLayout());

    //Create the toolbar.
    toolBar = new JToolBar();
   
    ImageIcon icon = new ImageIcon("images/pause.jpg");
    JButton button = new JButton(icon);
    toolBar.add(button);
    button.addActionListener(this);
    
    icon = new ImageIcon("images/play.jpg");
    button = new JButton(icon);
    toolBar.add(button);
    button.addActionListener(this);
    
    icon = new ImageIcon("images/next.jpg");
    button = new JButton(icon);
    toolBar.add(button);
    button.addActionListener(this);
  }

	public JToolBar getToolbar(){
		return toolBar;
	}
  
	public void initialise(Model model)
	{
		this.model = model;		
	}

	public void actionPerformed(ActionEvent e) {
		JButton source = (JButton)(e.getSource()); // detect which item was used
        String text = source.getIcon().toString();//e getText();
        System.err.println(text);
        if (text.equals("images/pause.jpg")){
        	model.setThreadContinue(false);
        }
        else if (text.equals("images/play.jpg"))
        {
        	model.setThreadContinue(true);
        }
        else if (text.equals("images/next.jpg"))
        {
        	model.setNext(true);
        }
	}
}